#include "BBContext.h"


BBContext::BBContext( void )
	:m_pState(NULL)
{

}

BBContext::BBContext( IState* state )
	:m_pState(state)
{

}

BBContext::~BBContext( void )
{

}

void BBContext::handler()
{
	if(m_pState)
		m_pState->handlerContext(this);
}

void BBContext::changeContextState(IState* state)
{
	if(m_pState)
	{
		m_pState = state;
		handler();
		addContextState(state);
	}
}

void BBContext::addContextState(IState* state)
{
	pContextIterator iter;
	bool isExist = false;
	for(iter=m_pStateList.begin(); iter!=m_pStateList.end();iter++)
	{
		if((*iter) == state)
		{
			isExist = true;
			return;
		}
	}
	if(!isExist)
		m_pStateList.push_back(state);
}

IState* BBContext::getCurrentContextState()
{
	return m_pState;
}

void BBContext::clear()
{
	m_pStateList.clear();
}

void BBContext::setTag(int var)
{
	m_iTag = var;
}

int BBContext::getTag()
{
	return m_iTag;
}